package com.itheima.controller;

import com.itheima.jopo.Dept;
import com.itheima.jopo.Result;
import com.itheima.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * DeptController
 *
 * @author liliudong
 * @version 1.0
 * @description 部门控制器
 * @date 2023/4/29 10:02
 */
@RestController
@RequestMapping("/depts")
public class DeptController {

    @Autowired
    private DeptService deptService;

    @GetMapping
    public Result selectDepts() {
        // 调用Service
        List<Dept> list = deptService.list();
        return Result.success(list);
    }

    // /depts{id}
    // /depts{id}
    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable String id) {
        // 通过ID删除
        deptService.removeById(id);
        return Result.success();
    }

    @PostMapping
    public Result addDepts(@RequestBody Dept dept) {
        deptService.addOne(dept);

        return Result.success();
    }

}
